package com.mornd.server.utils;

import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Set;

/**
 * @author mornd
 * @date 2021/3/31 - 17:41
 * redis工具类
 */
@Component
public class RedisUtil {
    @Resource
    private RedisTemplate<String,String> redisTemplate;

    @Bean
    public ValueOperations<String, String> getOpsForValue(){
         return redisTemplate.opsForValue();
    }

    public RedisTemplate<String, String> getRedisTemplate() {
        return redisTemplate;
    }

    /**
     * 删除所有用户的菜单信息
     */
    public void deleteMenuCache() {
        Set<String> keys = redisTemplate.keys("menu_" + "*");
        redisTemplate.delete(keys);

    }
}
